local ServerOHOH = _G.ServerOHOH;
local M = ServerOHOH.class.new(script, ServerOHOH.files.Server_PlayerComponent());
local function_list = ServerOHOH.function_list;
local PetTool=_G.CommonOHOH.load.PetTool();

function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);    
    self.DataBase=self.parent:GetComponent(ServerOHOH.load.Server_PlayerDataComponent())
    self.player=parent
end;

function M.dtor(self)
	M.super.dtor(self);
end;

--黄金制作
function M.GoldCraft(self,petId,count)
    assert(petId,"petId==null")
    assert(count,"count==null")
    assert(count>0,"count==0")
    local needCount=PetTool.GetMakeGoldMaxCount(self.parent)
    assert(count<=needCount,"count>"..needCount)
    local hadPetStore=self.DataBase:GetData("pets").had
    if not hadPetStore[petId] or hadPetStore[petId]<count then
        return false
    end
    local randList={}

    for i=1,needCount do
       table.insert(randList,false)
    end
    for i=1,count do
        randList[i]=true
    end

    local isSuccess= randList[math.random(1,#randList)]

    hadPetStore[petId]=hadPetStore[petId]-count
    if hadPetStore[petId]==0 then
        hadPetStore[petId]=nil
    end
    if isSuccess then
       local newPetId= PetTool.GetUpEvolutionPetIdByPetId(petId)
       if hadPetStore[newPetId] then
            hadPetStore[newPetId]=hadPetStore[newPetId]+1
       else
            hadPetStore[newPetId]=1
       end
    end
    
    PetTool.UpdateEquip(petId,hadPetStore,self.DataBase:GetData("pets").equip)

    self.DataBase:Execut(function()
	end);
    self.parent:SynchDataToClient("pets")

    self.player.PetEuqipUpdateEvent:Action()
    -- print("制作函数success:",isSuccess)
    return isSuccess
end

--黄金制作接口: 参数：petId，count(制作数量),返回值：ture（成功) or false(失败)
M:RegistFunction(function_list.gold_craft,M.GoldCraft)
return M